define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coupon/index' + location.search,
                    add_url: 'coupon/add',
                    edit_url: 'coupon/edit',
                    del_url: 'coupon/del',
                    multi_url: 'coupon/multi',
                    table: 'coupon',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: '序号'},
                        {field: 'name', title: __('Name')},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'use_amount', title: '满减基数'},
                        {field: 'count', title: '张数'},
                        {field: 'start_time', title: '领用开始时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: '领用结束时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'end_time', title: '优惠券到期时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'got_time', title: '领用人数'},
                        {field: 'use_time', title: '已使用人数'},
                        {field: 'status', title: '是否启用', operate:false, searchList: {"0":'否',"1":'是'}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible: false,
                commonSearch: false,
                search:true,
                onLoadSuccess:function(){
                    // 这里就是数据渲染结束后的回调函数
                    $(".btn-editone").data("area", ["100%","100%"]);
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});